package com.along.dev.rbac.controller;

import com.along.dev.rbac.dto.MenuDTO;
import com.along.dev.rbac.entity.Menu;
import com.along.dev.rbac.qo.MenuQO;
import com.along.dev.rbac.service.MenuService;
import com.along.utility.common.response.GeneralResult;
import com.along.utility.common.response.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/*
 * @Author: liujinyi
 * @DateTime: 2025/9/15 17:40
 */
@CrossOrigin
@RestController
@RequestMapping("/rbac/menu")
public class MenuController {
    @Autowired
    private MenuService menuService;

    @PostMapping("/find")
    public PageResult<MenuDTO> find(@RequestBody MenuQO menuQO) {
        return PageResult.success(menuService.find(menuQO, menuQO.getPage(), menuQO.getRows()));
    }

    @GetMapping("/tree")
    public GeneralResult<List<Menu>> getMenuTree() {
        return GeneralResult.success(menuService.getMenuTree());
    }

    @PostMapping("/save")
    public GeneralResult<MenuDTO> save(@RequestBody MenuDTO menuDTO) {
        menuService.save(menuDTO);
        return GeneralResult.success();
    }

    @PostMapping("/update")
    public GeneralResult<MenuDTO> update(@RequestBody MenuDTO menuDTO) {
        menuService.update(menuDTO);
        return GeneralResult.success();
    }

    @PostMapping("/delete")
    public GeneralResult<MenuDTO> delete(@RequestBody MenuDTO menuDTO) {
        menuService.delete(menuDTO);
        return GeneralResult.success();
    }

    @PostMapping("/updateStatus")
    public GeneralResult<MenuDTO> updateStatus(@RequestBody MenuDTO menuDTO) {
        menuService.updateStatus(menuDTO);
        return GeneralResult.success();
    }
}
